package pear.gui.table;

import java.awt.Color;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author Dingo
 */
public class IconCellRenderer extends JLabel implements TableCellRenderer {

    private Icon pause;
    private Icon play;
    private Icon stop;

    public IconCellRenderer() {
        pause = new ImageIcon(getClass().getResource("/resources/icons/bullet_blue.png"));
        stop = new ImageIcon(getClass().getResource("/resources/icons/bullet_red.png"));
        play = new ImageIcon(getClass().getResource("/resources/icons/bullet_green.png"));
        setText(null);
        setOpaque(true);
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        String SValue = (String) value;
        switch (SValue) {
            case "play":
                setIcon(play);
                break;
            case "stop":
                setIcon(stop);
                break;
            case "pause":
                setIcon(pause);
                break;
            default:
                setIcon(null);
                break;
        }
        if (isSelected) {
            setForeground(table.getSelectionForeground());
            setBackground(table.getSelectionBackground());
        } else {
            setForeground(table.getForeground());
            if (row % 2 == 1) {
                setBackground(table.getBackground());
            } else {
                setBackground(Color.WHITE);
            }
        }
        return this;
    }
}
